<template>
	<view class="">
		<view class="headtop"></view>
		<!-- 顶部 -->
		<view class="header" @click="binduser()">
			<view class="head_image">
				<image :src="avatar" style="border-radius: 50%;"></image>
			</view>
			<view class="head_name" v-if="userId">
				<view class="flex align-center justify-between">
					<view class="flex" @click.stop="navgo('/my/setting/xyf')">
						<view class="">{{nickName}}</view>
						<view class="text-df margin-left" style="font-weight: 200;">信用分:{{creditScore}}分</view>
					</view>
					<view class="qrCodeImg">
						<image @click.stop="getMyQrCode()" src="../../static/my/quCodeIcon.png" mode=""></image>
					</view>

				</view>
				<view v-if="shangxian=='否'">
					<view class="approve" v-if="checkCertification=='0'">实名认证审核中</view>
					<view class="approve" v-if="checkCertification=='1'">已实名</view>
					<view class="flex align-center approve" v-if="checkCertification=='2'">
						<view class="" @click.stop="bindapprove">实名认证未通过</view>
						<view class="margin-left" style="color: red;">{{checkCertificationMessage}}</view>
					</view>
					<view class="approve" @click.stop="bindapprove"
						v-if="checkCertification==null||checkCertification==''">未实名认证</view>
				</view>
			</view>
			<view class="head_name" v-if="!userId" @click.stop="goLogin">
				登录
			</view>
		</view>
		<view v-if="VipSwitch == '是'" class="vip flex align-center justify-center">
			<view class="vip-box flex align-center justify-between" @click="navgo('/my/vip/vip')">
				<view class="vip-box-l flex align-center">
					<image src="../../static/my/vipIconMy.png" mode="widthFix"></image>
					{{vipEndTime?'尊享接单特权':'开通会员享接单特权'}}
				</view>
				<view class="vip-box-r flex align-center">
					{{vipEndTime?'立即续费':'立即开通'}}
					<u-icon name="arrow-right" color="#8b4a24" size="24"></u-icon>
				</view>
			</view>
		</view>
		<!-- 收入和订单 -->
		<view class="shouru" v-if="shangxian=='否'">
			<view class="user_box">
				<view class="box">
					<view class="user_name" @click="navgo('/pages/riderMy/myAccount/myAccount')">
						<!-- <view style="width: 6rpx;height: 28rpx;background: #FE3B27;"></view> -->
						<u-section title="今日收入" :right="false" line-color="#FE3B27"></u-section>
					</view>
					<view class="user_price">{{indent.indentMoney?indent.indentMoney:0}} <text>元</text></view>
					<view class="user_tit ">今日收入金额</view>
				</view>
				<view class="box" @click="myOrders()">
					<view class="user_name">
						<!-- <view style="width: 6rpx;height: 28rpx;background: #009C66;"></view> -->
						<u-section title="订单统计" :right="false" line-color="#009C66"></u-section>
					</view>
					<view class="user_price">{{indent.indentCount?indent.indentCount:0}} <text>单</text></view>
					<view class="user_tit ">今日完成单量</view>
				</view>
			</view>
		</view>
		<!-- 我的列表 -->
		<view class="mylist ">
			<view class="list_box">
				<view class="list_left">
					<image src="../../static/my/kg.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">开始听单</view>
				</view>
				<u-switch v-model="checked" active-color="#70b4f7" inactive-color="#eee" size="45" @change="change"
					:loading="loading"></u-switch>
			</view>

			
			<view class="list_box" v-if="wxgzhSelect=='是'">
				<view class="list_left">
					<image src="../../static/my/kg.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">消息推送</view>
				</view>
				<u-switch v-model="checkedGzh" active-color="#70b4f7" inactive-color="#eee" size="45"
					@change="changeGzh" :loading="loadingGzh"></u-switch>
			</view>
			

			<view class="list_box" @click="navgo('/my/renzheng/index')" v-if="shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/renz.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">实名认证</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>

			<view class="list_box" @click="navgo('/my/wallet/index')" v-if="shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/qianbao.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">我的钱包</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="navgo('/my/wallet/baozhengjin')" v-if="DepositSwitch=='是' && shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/bzj.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">保证金</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="changekefu">
				<view class="list_left">
					<image src="../../static/my/kefu.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">联系客服</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="navgo('/my/setting/paihangbang')" v-if="shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/paihangb.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">师傅排行榜</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>

			<view class="list_box" @click="navgo('/my/appeal/index')" v-if="shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/shensu.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">违规申诉</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="navgo('/my/evaluate/index')" v-if="shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/pj.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">我的评价</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="navgo('/my/setting/xyf')">
				<view class="list_left">
					<image src="../../static/my/xyf.png" mode="scaleToFill" class="list_img"
						style="width: 50rpx;height: 50rpx;"></image>
					<view class="list_name">信用分明细</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<!-- #ifndef H5 -->
			<view class="list_box" @click="navgo('/my/setting/jinji')">
				<view class="list_left">
					<image src="../../static/my/jg.png" mode="scaleToFill" class="list_img"
						style="width: 50rpx;height: 50rpx;"></image>
					<view class="list_name">紧急报警</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<!-- #endif -->

			<view class="list_box" @click="navgo('/my/help/trainingList')">
				<view class="list_left">
					<image src="../../static/my/hellp.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">司机指南</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="navgo('/my/setting/index')">
				<view class="list_left">
					<image src="../../static/my/set.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">系统设置</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
		</view>

		<!-- 师傅二维码弹窗 -->
		<u-popup v-model="showQrcode" mode="center" closeable border-radius="14" width="600rpx">
			<view class="showQrcode-title">扫我下单</view>
			<view class="showQrcode-img">
				<image :src="qrCodeImg" mode="aspectFill"></image>
			</view>
		</u-popup>
		<!-- 公众号二维码弹框 -->
		<u-popup v-model="gzhQrcode" mode="center" closeable border-radius="14" width="600rpx">
			<view class="showQrcode-title">扫码关注</view>
			<view class="showQrcode-img">
				<image :src="gzhcodeImg" mode="aspectFill"></image>
			</view>
		</u-popup>
		<!-- 麦克风权限弹框 -->
		<u-popup :show="isShowTipImgs" zIndex="99999999" mode="top">
			<view class="tipsmkf">
				申请麦克风权限，便于您使用该功能上传您的语音，
			</view>
		</u-popup>
	</view>
</template>

<script>
	// #ifdef H5
	var recorder; // 定义一个MediaRecorder对象
	var stream; //定义一个音频流的对象
	var chunks = []; // 定义一个用于存储音频数据片段的数组
	// #endif
	import configdata from '@/common/config.js';
	export default {
		onShareAppMessage(res) { //发送给朋友
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		data() {
			return {
				//录音相关参数
				// #ifndef H5
				//H5不能录音
				RECORDER: uni.getRecorderManager(),
				// #endif
				isShowTipImgs: false,
				//播放语音相关参数
				AUDIO: uni.createInnerAudioContext(),
				playMsgid: null,
				VoiceTimer: null,
				contentUrl: '',
				recordLength: '',
				voicePaths: '',
				voicePath: '',
				blobData: '',
				recordTimer: null,

				showQrcode: false, //是否显示二维码
				tuiguang: '',
				tuiguangImg: '',
				show: false,
				title: '我的',
				information: {}, //个人信息
				daySr: '',
				orders: '',
				indent: {},

				avatar: '../../static/logo.png',
				nickName: '匿名',
				checkCertification: '',
				userId: '',
				token: '',
				shangxian: '是',
				checkCertificationMessage: '',

				checked: false,
				loading: false,
				// 中间变量，避免在watch中多次回调，造成无限循环
				controlStatus: false,
				creditScore: 0,
				arr: [],
				showModal1: true,
				qrCodeImg: '',
				VipSwitch: '是',
				vipEndTime: '',
				DepositSwitch: '是',
				gzhQrcode: false,
				gzhcodeImg: '',
				checkedGzh: false,
				controlStatusGzh: false,
				loadingGzh: false,
				riderAccountOpenId: '',
				wxgzhSelect:'否'
			}
		},
		onHide() {
			console.log('离开卸载')
			this.voiceEnd()
			this.AUDIO.stop();
		},
		onLoad() {
			
			this.VipSwitch = uni.getStorageSync('VipSwitch')
			this.DepositSwitch = uni.getStorageSync('DepositSwitch')
			this.shangxian = uni.getStorageSync('shangxian')
			this.$Request.getT('/app/common/type/276').then(res => {
				if (res.code === 0) {
					uni.setStorageSync('tuiguang', res.data.value)
					this.tuiguang = res.data.value;
				}
			});
			this.$Request.getT('/app/common/type/277').then(res => {
				if (res.code === 0) {
					uni.setStorageSync('tuiguangImg', res.data.value)
					this.tuiguangImg = res.data.value;
				}
			});
			// 公众号二维码	2
			this.$Request.getT('/app/common/type/2').then(res => {
				if (res.code === 0) {
					this.gzhcodeImg = res.data.value;
				}
			});
			this.$Request.getT('/app/common/type/416').then(res => {
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.wxgzhSelect =  res.data.value
					}
				}
			});
			this.$Request.getT('/app/common/type/268').then(res => { //师傅端订单状态通知 268

				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arr.push(res.data.value)
					}
				}
			})
			this.$Request.getT('/app/common/type/338').then(res => { //师傅新订单通知 338
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arr.push(res.data.value)
					}
				}
			})
			let that = this
			// #ifndef H5
			//录音开始事件
			that.RECORDER.onStart((e) => {
				console.log('监听开始录音' + e)
			})
			//录音结束事件
			that.RECORDER.onStop((e) => {
				console.log('监听结束录音' + e)
				that.recordEnd(e);
			})
			// #endif
			if (uni.getStorageSync('orderIndentId')) {
				that.StartMp()
			}
		},
		onShow() {

			this.token = this.$queue.getData('token');
			this.userId = this.$queue.getData('userId');
			if (this.token) {
				this.$Request.getT('/app/indent/getRiderIndentList?page=1&limit=2&indentState=2').then(
					res => {
						if (res.code === 0) {
							if (res.data.records && res.data.records.length != 0) {
								this.StartMp()
							} else {
								uni.removeStorageSync('orderIndentId')
							}
						}
					});
				this.shouru()
				this.getVip()
				this.getUserInfo();

				if (this.showModal1) {
					// #ifdef MP-WEIXIN
					this.openMsg()
					// #endif
				}
			} else {
				// this.goLogin();
				this.userId = ''
				this.indent = []
				this.avatar = '../../static/logo.png'
				this.nickName = ''
			}


		},
		methods: {
			StartMp() { //  开始录音
				let that = this
				// #ifdef APP
				// 在弹出选择弹框之前先判断一下是否获取了相册权限
				const sysInfo = uni.getSystemInfoSync()
				if (sysInfo.osName == 'ios') { //ios

				} else { //安卓
					var Manifest = plus.android.importClass("android.Manifest");
					var MainActivity = plus.android.runtimeMainActivity();
					let flag = MainActivity.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
					console.log(flag); // 查看是否拥有相机权限 -1/0
					if (flag == -1) { //没有授权
						that.isShowTipImgs = true
						plus.android.requestPermissions(['android.permission.RECORD_AUDIO'], (success) => {
							that.isShowTipImgs = false
						}, (err) => {
							that.isShowTipImgs = false
						})
						return
					} else {
						that.isShowTipImgs = false
					}

				}
				// #endif
				// #ifdef H5
				if (stream) {
					stream.getTracks().forEach((track) => track.stop())
					stream = null
				}
				if (recorder) {
					recorder = null
				}
				that.recordLength = 0
				that.voicePaths = '';
				that.voicePath = '';
				that.startRecord()
				// #endif
				// #ifndef H5
				that.RECORDER.start({
					format: "mp3"
				}); //录音开始,
				that.recordBegin()
				// #endif
			
			},
			//开始录音
			startRecord: async function() {
				let _this = this
				// 获取麦克风音频数据流
				stream = await navigator.mediaDevices.getUserMedia({
					audio: true
				})
				// 初始化MediaRecorder对象
				recorder = new MediaRecorder(stream);
				// console.log('asdsad___' + recorder)
				// alert('asdsad___' + recorder)
				// 将 stream 转成 blob 来存放
				recorder.ondataavailable = (blobEvent) => {
					chunks.push(blobEvent.data);
				}
				// 停止时生成预览的 blob url
				recorder.onstop = () => {
					const blob = new Blob(chunks, {
						type: 'audio/mp3'
					})
					_this.voicePaths = blob;
					_this.blobData = blob;

				}
				recorder.start();
				_this.recordBegin()
			},
			//录音开始UI效果
			recordBegin() {
				this.recordLength = 0;
				this.recordTimer = setInterval(() => {
					this.recordLength++;
				}, 1000)
			},
			// 结束录音
			voiceEnd() {
				//原生录音停止
				// #ifdef H5
				//停止录音
				if (recorder.state != "inactive") {
					recorder.stop();
				}
				//把音频流也停止掉
				stream.getTracks().forEach((track) => track.stop())
				this.uplodMp3(this.voicePaths);
				// #endif

				// #ifndef H5
				this.RECORDER.stop(); //录音结束
				// #endif

			},
			//录音结束(回调文件)
			recordEnd(e) {
				clearInterval(this.recordTimer);
				// uni.showLoading({
				// 	title: '发送中'
				// });
				console.log(this.recordLength, e.tempFilePath && indentId && this.recordLength > 3)
				let indentId = uni.getStorageSync('orderIndentId')
				if (e.tempFilePath && indentId && this.recordLength > 3) {
					uni.uploadFile({ // 上传接口
						// url: this.config("APIHOST1") + '/alioss/upload', //真实的接口地址
						url: this.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + indentId, //真实的接口地址
						// url: 'https://shifu.tadaijia.cn/alioss/upload', //真实的接口地址
						filePath: e.tempFilePath,
						name: 'file',
						success: (uploadFileRes) => {
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {
								// uni.showToast({
								// 	title: '上传成功',
								// 	icon: "none"
								// });

							} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}

						},
						fail: (err) => {
							console.log('err' + err)
						}
					});

				}
			},
			//上传mp3格式的音频
			uplodMp3(recordPath) {
				let _this = this;
				clearInterval(_this.recordTimer);

				let indentId = uni.getStorageSync('orderIndentId')
				if (indentId && _this.blobData && _this.recordLength > 3) {
					uni.uploadFile({ // 上传接口
						url: _this.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + indentId, //真实的接口地址
						file: _this.blobData,
						name: 'file',
						success: (uploadFileRes) => {
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}
						}
					});
				}
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},


			//获取师傅二维码
			getMyQrCode() {
				let that = this
				let userId = uni.getStorageSync('userId')
				uni.downloadFile({
					url: configdata.APIHOST + '/app/invite/riderQr?userId=' + userId,
					success(res) {
						that.qrCodeImg = res.tempFilePath
						that.showQrcode = true
					}
				})
			},
			// 是否开启微信公众号推送 switch打开或者关闭时触发，值为true或者false 
			changeGzh(status) {

				if (this.checkedGzh == false) {
					if (this.controlStatusGzh == true) {
						this.controlStatusGzh = false;
						return;
					}
					// 重新打开switch，并让它处于加载中的状态
					this.checkedGzh = true;
					if (uni.getStorageSync('token')) {
						if (this.riderAccountOpenId) {
							this.loadingGzh = true;
							this.getRestultFromServerGzh();
						} else {
							this.gzhQrcode = true
						}

					} else {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}

					// 模拟向后端发起请求
				} else if (this.checkedGzh == true) {
					if (this.controlStatusGzh == true) {
						this.controlStatusGzh = false;
						return;
					}
					// 重新关闭switch，并让它处于加载中的状态
					this.checkedGzh = false;
					// 模拟向后端发起请求
					if (uni.getStorageSync('token')) {
						if (this.riderAccountOpenId) {
							this.loadingGzh = true;
							this.getRestultFromServer1Gzh();
						} else {
							this.gzhQrcode = true
						}
					} else {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				}
			},
			getRestultFromServerGzh() {
				this.controlStatusGzh = true;
				// 后端允许用户关闭switch，设置checked为false，结束loading状态
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要关闭公众号推送吗',
					complete: function(ret) {
						if (ret.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								title: '修改中...',
							})
							let userId = uni.getStorageSync('userId')
							let data = {
								isWxSend: 2,
								userId: userId
							}
							that.$Request.postJson("/app/user/updateUser", data).then(
								res => {
									uni.hideLoading();
									that.loadingGzh = false;
									that.controlStatusGzh = false
									if (res.code === 0) {
										that.checkedGzh = false;

										that.getUserInfo();
									} else {
										that.$queue.showToast(res.msg)
									}
								});
						} else if (ret.cancel) {
							console.log('用户点击取消');
							that.checkedGzh = true;
							that.loadingGzh = false;
							that.controlStatusGzh = false
						}
					},
				});
			},
			getRestultFromServer1Gzh() {
				// 通过定时器模拟向后端请求
				this.controlStatusGzh = true;
				// 后端允许用户关闭switch，设置checked为false，结束loading状态
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要开启公众号推送吗',
					complete: function(ret) {
						if (ret.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								title: '修改中...',
							})
							let userId = uni.getStorageSync('userId')
							let data = {
								isWxSend: 1,
								userId: userId
							}
							that.$Request.postJson("/app/user/updateUser", data).then(
								res => {
									uni.hideLoading();
									that.loadingGzh = false;
									that.controlStatusGzh = false
									if (res.code === 0) {
										that.checkedGzh = true;
										that.getUserInfo();
									} else {
										that.$queue.showToast(res.msg)
									}
								});
						} else if (ret.cancel) {
							that.loadingGzh = false;
							console.log('用户点击取消');
							that.checkedGzh = false;
							that.controlStatusGzh = false
						}
					}
				});
			},

			// switch打开或者关闭时触发，值为true或者false
			change(status) {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				if (this.checked == false) {
					if (this.controlStatus == true) {
						this.controlStatus = false;
						return;
					}
					// 重新打开switch，并让它处于加载中的状态
					this.checked = true;
					if (uni.getStorageSync('token')) {
						this.loading = true;
						this.getRestultFromServer();
					} else {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}

					// 模拟向后端发起请求


				} else if (this.checked == true) {
					if (this.controlStatus == true) {
						this.controlStatus = false;
						return;
					}
					// 重新关闭switch，并让它处于加载中的状态
					this.checked = false;
					// 模拟向后端发起请求
					if (uni.getStorageSync('token')) {
						this.loading = true;
						this.getRestultFromServer1();
					} else {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				}
			},
			getRestultFromServer() {
				this.controlStatus = true;
				// 后端允许用户关闭switch，设置checked为false，结束loading状态
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要下线吗',
					complete: function(ret) {
						if (ret.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								title: '修改中...',
							})
							that.$Request.postT("/app/user/updateLine").then(res => {
								uni.hideLoading();
								that.loading = false;
								that.controlStatus = false
								if (res.code === 0) {
									that.checked = false;

									that.getUserInfo();
								} else {
									that.$queue.showToast(res.msg)
								}
							});
						} else if (ret.cancel) {
							console.log('用户点击取消');
							that.checked = true;
							that.loading = false;
							that.controlStatus = false
						}
					},
				});
			},
			getRestultFromServer1() {
				// 通过定时器模拟向后端请求
				this.controlStatus = true;
				// 后端允许用户关闭switch，设置checked为false，结束loading状态
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要上线吗',
					complete: function(ret) {
						if (ret.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								title: '修改中...',
							})
							that.$Request.postT("/app/user/updateLine").then(res => {
								uni.hideLoading();
								that.loading = false;
								that.controlStatus = false
								if (res.code === 0) {
									that.checked = true;
									that.getUserInfo();
								} else {
									that.$queue.showToast(res.msg)
								}
							});
						} else if (ret.cancel) {
							that.loading = false;
							console.log('用户点击取消');
							that.checked = false;
							that.controlStatus = false
						}
					}
				});
			},
			//联系客服
			changekefu() {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				let kefu = this.$queue.getData('kefu'); // 用户端联系方式 1 手机号 2企业微信
				let kefuPhone = this.$queue.getData('kefuPhone');
				if (kefu == 1) {
					uni.makePhoneCall({
						phoneNumber: kefuPhone //仅为示例
					});
				} else if (kefu == 2) {
					// #ifdef MP-WEIXIN
					let that = this
					try {
						wx.openCustomerServiceChat({
							extInfo: {
								url: that.$queue.getData('kefuUrl')
							},
							corpId: that.$queue.getData('kefuAppId'),
							success(res) {},
							fail(res) {
								console.error(res)
							}
						})
					} catch (error) {
						console.error("catchcatch" + error)
						uni.showToast({
							title: '请更新至微信最新版本'
						});
					}
					// #endif
					// #ifndef MP-WEIXIN
					let url = this.$queue.getData('kefuUrl');
					if (url.indexOf('/pages/') !== -1 || url.indexOf('/pageA/') !== -1 || url.indexOf('/my/') !== -1) {
						uni.navigateTo({
							url
						});
					} else {
						//#ifndef H5
						uni.navigateTo({
							url: '/pages/index/webView?url=' + url
						});
						//#endif
						//#ifdef H5
						window.location.href = url;
						//#endif
					}
					// #endif
				} else if (kefu == 3) {
					uni.navigateTo({
						url: '/my/kefu/index'
					});
				}
			},
			// 查看今日收入
			profit() {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				if (!this.userId) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/riderMy/profit'
				})
			},
			// 查看订单统计
			myOrders() {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				if (!this.userId) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/riderMy/order'
				})
			},
			bindapprove() {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				uni.navigateTo({
					url: '/pages/riderMy/approve/approve'
				})
			},
			navgo(e) {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				let that = this
				if (that.token) {
					uni.navigateTo({
						url: e
					})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			binduser() {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				let token = this.$queue.getData('token');
				if (!token) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return;
				}
				uni.navigateTo({
					url: '/pages/riderMy/userinfo'
				});
			},
			// 获取会员详情
			getVip() {
				this.$Request.getT("/app/UserVip/selectUserVip").then(res => {
					if (res.code == 0 && res.data) {
						this.vipEndTime = res.data.endTime
					}
				});
			},
			// 获取个人信息
			getUserInfo() {
				this.$Request.getT("/app/userinfo/findUserInfoById").then(res => {
					if (res.code == 0) {
						this.$nextTick(function() {
							this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
							uni.getStorageSync('avatar', res.data.avatar)
							this.nickName = res.data.nickName
							this.creditScore = res.data.creditScore
							this.checkCertification = res.data.checkCertification
							this.checkCertificationMessage = res.data.checkCertificationMessage
							uni.setStorageSync('checkCertification', res.data.checkCertification)

							uni.setStorageSync('zhiFuBao', res.data.zhiFuBao)
							uni.setStorageSync('zhiFuBaoName', res.data.zhiFuBaoName)
							// console.log(this.checkCertification, '实名认证')
							this.userId = res.data.userId
							uni.setStorageSync('userId', res.data.userId)

							if (res.data.onLineFlag != 2) {
								this.checked = true
							} else {
								this.checked = false
							}

							if (res.data.isWxSend == 1) {
								this.checkedGzh = true
							} else {
								this.checkedGzh = false
							}
							this.riderAccountOpenId = res.data.riderAccountOpenId


						})
					} else {
						this.$queue.logout();
						uni.showModal({
							showCancel: false,
							title: '登录失败',
							content: res.msg,
						});
					}
				});
			},
			// 今日收入、订单量
			shouru() {
				this.$Request.getT('/app/userinfo/findIncome').then(res => {
					if (res.code == 0) {
						// this.daySr = res.data.income
						// this.orders = res.data.indentCount
						this.indent = res.data
					}
					console.log('res', res)

				});
			},
			// 跳转去登录
			goLogin() {
				// this.$queue.setData('href', '/pages/my/index');
				uni.navigateTo({
					url: '/pages/login/login'
				});
			},
			//退出登录
			TuiLogin() {
				let that = this

				if (that.userId) {
					uni.showModal({
						title: '提示',
						content: '确认退出登录吗?',
						success: function(res) {
							if (res.confirm) {
								uni.removeStorageSync('userId')
								uni.removeStorageSync('token')
								uni.removeStorageSync('avatar')
								uni.removeStorageSync('nickName')
								uni.removeStorageSync('phone')
								uni.removeStorageSync('invitationCode')
								uni.removeStorageSync('inviterCode')
								uni.removeStorageSync('platform')
								uni.removeStorageSync('sex')
								uni.removeStorageSync('zhiFuBao')
								uni.removeStorageSync('zhiFuBaoName')
								uni.removeStorageSync('checkCertification')

								// uni.navigateBack()
								uni.redirectTo({
									url: '/pages/index/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/login/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}


			},
			// 开启订阅消息
			openMsg() {
				console.log('订阅消息')
				var that = this
				uni.getSetting({
					withSubscriptions: true, //是否获取用户订阅消息的订阅状态，默认false不返回
					success(ret) {
						console.log(ret.subscriptionsSetting, '------------------')
						// if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
						if (ret.subscriptionsSetting.itemSettings) {
							uni.setStorageSync('sendMsg', true)
							uni.openSetting({ // 打开设置页 
								success(rea) {
									console.log(rea.authSetting)
								}
							});
						} else { // 用户没有点击“总是保持以上，不再询问”则每次都会调起订阅消息
							console.log(99999)
							uni.setStorageSync('sendMsg', false)
							uni.showModal({
								title: '提示',
								content: '为了更好的体验,请绑定消息推送',
								confirmText: '确定',
								cancelText: '取消',
								success: function(res) {
									if (res.confirm) {
										console.log(that.arr)
										wx.requestSubscribeMessage({
											tmplIds: that.arr,
											success(re) {
												console.log(JSON.stringify(re),
													'++++++++++++++')
												var datas = JSON.stringify(re);
												if (datas.indexOf("accept") != -1) {
													console.log(re)
													// uni.setStorageSync('sendMsg', true)
												}
											},
											fail: (res) => {
												console.log(res)
											}
										})
										// uni.setStorageSync('sendMsg', true)
										console.log('确认')
										that.showModal1 = false
									} else if (res.cancel) {
										console.log('取消')
										// uni.setStorageSync('sendMsg', false)
										that.showModal1 = true
									}
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	/deep/.u-icon__icon {
		font-size: 35rpx !important;
		font-weight: bold !important;
	}

	/deep/.u-title {
		color: #000000 !important;
	}

	/deep/.u-navbar-fixed {
		background: none !important;
	}

	.tipsmkf {
		width: 100%;
		padding: 30rpx;
		font-size: 26rpx;
		color: #333333;
		position: fixed;
		top: 50rpx;
		left: 0;
		z-index: 99999 !important;
		background-color: #ffffff;
	}

	page {
		background: #F5F5F5;
	}

	.showQrcode-title {
		width: 100%;
		text-align: center;
		font-size: 34rpx;
		font-weight: bold;
		margin-top: 24rpx;


	}

	.showQrcode-img {
		width: 500rpx;
		height: 500rpx;
		margin: 30rpx auto;
		margin-bottom: 40rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}

	.headtop {
		background: linear-gradient(0deg, #F5F5F5 0%, #6CB3FC 100%);
		height: 400rpx;
		position: fixed;
		/* #ifdef H5 */
		top: 0rpx;
		padding-top: 30rpx;
		/* #endif */
		/* #ifndef H5 */
		top: 0rpx;
		/* #endif */
		left: 0;
		right: 0;
		z-index: 0;
	}

	/* 顶部 */
	.header {
		width: 100%;
		height: 150rpx;
		display: flex;
		align-items: center;


	}

	.head_image {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.head_image image {
		width: 90rpx;
		height: 90rpx;
	}

	.head_name {
		flex: 4;
		position: relative;
		font-size: 36rpx;
		font-weight: bold;
		color: #FFFFFF;
	}

	.qrCodeImg {
		width: 60rpx;
		height: 60rpx;
		margin-right: 30rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 50%;
		}
	}



	.approve {
		font-size: 24rpx;
		font-weight: 500;
	}

	/* 用户信息 */
	.shouru {
		border-radius: 24rpx;
		overflow: hidden;
		width: 93%;
		margin: 0 auto;
		background: #ffffff;
		position: relative;
		z-index: 99;
	}

	.user_box {
		display: flex;
		height: 210rpx;
		padding: 0 20rpx 0 30rpx;

	}

	.box {
		flex: 1;
		/* margin-left: 40rpx; */
		margin-top: 40rpx;
	}

	.user_price {
		font-size: 44rpx;
		margin-top: 10rpx;
	}

	.user_price text {
		font-size: 21rpx;
		margin-left: 10rpx;
	}

	.user_tit {
		color: #B3B3B3;
		font-size: 21rpx;
		margin-top: 10rpx;
	}

	/deep/.u-section__title {
		font-weight: 500 !important;
		color: #333333 !important;
		font-size: 14px !important;
		padding-left: 10px;
	}

	/* 我的列表 */
	.mylist {
		// width: 93%;
		// margin: 0 auto;
		margin: 20rpx 30rpx;
		background-color: #FFFFFF;
		border-radius: 23rpx;
		padding: 20rpx 30upx;
		position: relative;
		z-index: 99;
	}

	.list_box {
		/* width: 90%; */
		/* margin: 0 auto; */
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 95rpx;
	}

	.list_left {
		flex: 1;
		display: flex;
		justify-content: left;
		align-items: center;
	}

	.list_img {
		width: 56rpx;
		height: 56rpx;
		margin-right: 18rpx;
	}

	.list_name {
		font-size: 25rpx;
		letter-spacing: 2rpx;
	}


	.list_right {
		width: 12rpx;
		height: 20rpx;
	}

	.user_name {
		display: flex;
		align-items: center;
	}

	// 会员样式
	.vip {
		width: 100%;
		height: 110rpx;
		position: relative;
		margin-bottom: 20rpx;

		.vip-box {
			width: 700rpx;
			height: 100%;
			background: linear-gradient(to right, #ebd6a6, #f3e0c0);
			border-radius: 24rpx;
			padding: 0 30rpx;
		}

		.vip-box-l {
			color: #8b4a24;
			font-size: 30rpx;
			font-weight: 500;

			image {
				width: 40rpx;
				margin-right: 10rpx;
			}
		}

		.vip-box-r {
			color: #8b4a24;
			font-size: 26rpx;
			font-weight: 500;
		}
	}
</style>